package com.lin.ovc.pomodoro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lin.ovc.pomodoro.entity.Plan;
import com.lin.ovc.pomodoro.entity.Task;
import com.lin.ovc.pomodoro.entity.dto.TaskForm;
import com.lin.ovc.pomodoro.mapper.TaskMapper;
import com.lin.ovc.pomodoro.service.TaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lin
 * @since 2024-07-25
 */
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService {

    @Override
    public boolean save(TaskForm form) {
        Task task = new Task();
        BeanUtils.copyProperties(form, task);
        boolean flag = this.save(task);
        if(flag)return true;
        return false;
    }

    @Override
    public boolean update(TaskForm form) {
        Task task = new Task();
        BeanUtils.copyProperties(form, task);
        boolean flag = this.updateById(task);
        if(flag)return true;
        return false;
    }

    @Override
    public List<Task> list(long id) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("plan_id",id);
        return this.list(wrapper);
    }
}
